//
//  JKRFeedStatusView.m
//  JKRFeedDemo
//
//  Created by Lucky on 2017/12/10.
//  Copyright © 2017年 Lucky. All rights reserved.
//

#import "JKRFeedStatusView.h"

@interface JKRFeedStatusView ()

@property (nonatomic, strong) YYLabel *topLabel;
@property (nonatomic, strong) YYLabel *bottomLabel;

@end

@implementation JKRFeedStatusView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    @weakify(self);
    self.backgroundColor = [UIColor whiteColor];
    _topLabel = [self _creatYYLabel];
    _topLabel.highlightTapAction = ^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [weak_self highLightClickWithText:text range:range];
    };
    [self addSubview:_topLabel];
    _bottomLabel = [self _creatYYLabel];
    [self addSubview:_bottomLabel];
    
    return self;
}

- (void)setLayout:(JKRFeedStatusLayout *)layout {
    _layout = layout;
    self.hidden = !layout.show;
    if (!layout.show) {
        return;
    }
    self.frame = layout.stautsFrame;
    self.topLabel.frame = layout.topLabelFrame;
    self.topLabel.textLayout = layout.topLabelLayout;
    self.bottomLabel.frame = layout.bottomLabelFrame;
    self.bottomLabel.textLayout = layout.bottomLabelLayout;
}

- (YYLabel *)_creatYYLabel {
    YYLabel *label = [YYLabel new];
    label.ignoreCommonProperties = YES;
    label.fadeOnAsynchronouslyDisplay = YES;
    label.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    return label;
}

- (void)highLightClickWithText:(NSAttributedString *)text range:(NSRange)range {
    YYTextHighlight *highlight = [text attribute:YYTextHighlightAttributeName atIndex:range.location];
    NSDictionary *info = highlight.userInfo;
    if (info.count == 0) {
        return;
    }
    
    if (info[kFeedTopClickUser]) {
        NSLog(@"用户主页");
        return;
    }
    if (info[kFeedTopClickCandidateList]) {
        NSLog(@"大神列表");
        return;
    }
}

@end
